.SUFFIXES: .c .o .lo

COMPILE = $(CC) $(CFLAGS)
INC_PATH = -I../common
LIB_PATH = $(LIBS) -lfastcommon -lserverframe
TARGET_LIB = $(TARGET_PREFIX)/$(LIB_VERSION)

FAST_SHARED_OBJS = ../common/fs_global.lo ../common/fs_proto.lo \
                   ../common/fs_func.lo ../common/fs_cluster_cfg.lo \
                   fs_client.lo client_func.lo client_global.lo \
				   client_proto.lo simple_connection_manager.lo

FAST_STATIC_OBJS = ../common/fs_global.o ../common/fs_proto.o \
                   ../common/fs_func.o ../common/fs_cluster_cfg.o \
                   fs_client.o client_func.o client_global.o  \
				   client_proto.o simple_connection_manager.o

HEADER_FILES = ../common/fs_types.h ../common/fs_global.h ../common/fs_proto.h \
               ../common/fs_func.h ../common/fs_cluster_cfg.h fs_client.h  \
               client_types.h client_func.h client_global.h client_proto.h \
               simple_connection_manager.h

ALL_OBJS = $(FAST_STATIC_OBJS) $(FAST_SHARED_OBJS)

ALL_PRGS = 
SHARED_LIBS = libfsclient.so
STATIC_LIBS = libfsclient.a
ALL_LIBS = $(SHARED_LIBS) $(STATIC_LIBS)

all: $(ALL_OBJS) $(ALL_PRGS) $(ALL_LIBS)
libfsclient.so: $(FAST_SHARED_OBJS)
	$(COMPILE) -o $@ -shared $(FAST_SHARED_OBJS) $(LIB_PATH)
libfsclient.a: $(FAST_STATIC_OBJS)
	ar rcs $@ $(FAST_STATIC_OBJS)
.o:
	$(COMPILE) -o $@ $<  $(FAST_STATIC_OBJS) $(LIB_PATH) $(INC_PATH)
.c:
	$(COMPILE) -o $@ $<  $(FAST_STATIC_OBJS) $(LIB_PATH) $(INC_PATH)
.c.o:
	$(COMPILE) -c -o $@ $<  $(INC_PATH)
.c.lo:
	$(COMPILE) -c -fPIC -o $@ $<  $(INC_PATH)
install:
	mkdir -p $(TARGET_LIB)
	mkdir -p $(TARGET_PREFIX)/lib
	mkdir -p $(TARGET_PREFIX)/include/faststore/client

	install -m 755 $(SHARED_LIBS) $(TARGET_LIB)
	install -m 644 $(HEADER_FILES) $(TARGET_PREFIX)/include/faststore/client
	@BUILDROOT=$$(echo "$(TARGET_PREFIX)" | grep BUILDROOT); \
	if [ -z "$$BUILDROOT" ] && [ ! -e $(TARGET_PREFIX)/lib/libfsclient.so ]; then ln -s $(TARGET_LIB)/libfsclient.so $(TARGET_PREFIX)/lib/libfsclient.so; fi
clean:
	rm -f $(ALL_OBJS) $(ALL_PRGS) $(ALL_LIBS)

